package cn.lj.user.controller;


import cn.lj.base.Exception.BusinessException;
import cn.lj.base.util.AjaxResult;
import cn.lj.user.dto.LoginDto;
import cn.lj.user.service.ILoginInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
@Api(tags = "用户登录接口",description = "用户登录接口实现")
public class LoginInfoController {

    @Autowired
    private ILoginInfoService loginInfoService;

    @PostMapping("/account")
    @ApiOperation(value = "人员登录",notes = "测试前台后台人员账号登录")
    public AjaxResult login(@RequestBody LoginDto loginDto){
        try {
            Map<String,Object> map = loginInfoService.login(loginDto);
            return AjaxResult.me().setData(map);/*返回map给前台*/
        }catch (BusinessException e){
            return AjaxResult.me().setAjaxResult(e.getMessage());
        }catch (Exception e){
            return AjaxResult.me().setAjaxResult(e.getMessage());
        }
    }
    /*
    * Map:  binderUrl	"http://bugtracker.itsource.cn/binder.html"
            code	"0416vuFa1EVItB0iM0Ia1bK4En26vuF6"
    * */
    @PostMapping("/wechat")
    @ApiOperation(value = "用户扫码登录登录",notes = "测试用户扫码登录")
    public AjaxResult wechat(@RequestBody Map<String,String> map){
        try {
            return loginInfoService.wechat(map);
        }catch (Exception e){
            return AjaxResult.me().setAjaxResult(e.getMessage());
        }
    }
    @PostMapping("/binder")
    @ApiOperation(value = "用户扫码绑定",notes = "测试用户扫码登录绑定")
    public AjaxResult binder(@RequestBody Map<String,String> map){
        //System.out.println(map);
        try {
           return loginInfoService.binder(map);
        }catch (Exception e){
            return AjaxResult.me().setAjaxResult(e.getMessage());
        }
    }
}
